﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeadExpress.Models.ViewPages;

namespace LeadExpress.Areas.Management.Controllers
{
    public class DashboardController : Controller
    {
        // Create an instance of user manage
        LeadExpress.Repository.DashboardManagementRepository repository = new LeadExpress.Repository.DashboardManagementRepository();

        #region #Product Dashboard
        // GET: /Management/Dashboard/
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Index()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModel(Helpers.Constant.HOME, "SuperAdministrator", "PRODUCT");

            return View(model);
        }
        // GET: /Management/Dashboard/
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult ProductApproval()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPA(Helpers.Constant.HOME, "SuperAdministrator", 50);

            return View(model);
        }

        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult GetProduct(string startDate)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            DateTime currentDate = DateTime.Parse(startDate);

            model = repository.GetModel(currentDate, "PRODUCT");

            return Json(model);
        }

        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult ProductFolow()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModel("PRODUCT");

            return Json(model);
        }

        // Ajax function post
        [HttpPost]
        public ActionResult SetProduct(int id)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPAApproved(Helpers.Constant.HOME, "SuperAdministrator", 50, id);

            return Json(model);
        }
        [HttpPost]
        public ActionResult DeleteProduct(int id)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPADelete(Helpers.Constant.HOME, "SuperAdministrator", 50, id);

            return Json(model);
        }
        
        // Group: Transaction
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult PATransaction()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPATransaction(Helpers.Constant.HOME, "SuperAdministrator", 50);

            return View(model);
        }

        // Ajax function post
        [HttpPost]
        public ActionResult SetProductTransaction(int id)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPATransactionApproved(Helpers.Constant.HOME, "SuperAdministrator", 50, id);

            return Json(model);
        }
        [HttpPost]
        public ActionResult DeleteProductTransaction(int id)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPATransactionDelete(Helpers.Constant.HOME, "SuperAdministrator", 50, id);

            return Json(model);
        }

        #endregion

        #region #Advertising Dashboard
        //
        // GET: /Management/Dashboard/
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Advertise()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModel(Helpers.Constant.HOME, "SuperAdministrator", "BANNER");

            return View(model);
        }

        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult GetBanner(string startDate)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            DateTime currentDate = DateTime.Parse(startDate);

            model = repository.GetModel(currentDate, "BANNER");

            return Json(model);
        }

        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult BannerFolow()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModel("BANNER");

            return Json(model);
        }
        #endregion
    }
}
